package com.jd.platform.gobrs.client.manager;

import com.jd.platform.gobrs.client.handler.CacheHandler;
import com.jd.platform.gobrs.client.handler.CacheHandlerFactory;
import com.jd.platform.gobrs.common.enums.CacheHandlerEnums;

/**
 * @program: gobrs
 * @ClassName ManualCacheManager
 * @description:
 * @author: sizegang
 * @create: 2022-01-08 16:26
 * @Version 1.0
 **/
public class ManualCacheManager extends AbstractCacheManager{

    private CacheHandler manualCache = CacheHandlerFactory.getInstance(CacheHandlerEnums.MANUAL_CACHE.getType());

//    ReentrantLock lock = new ReentrantLock(false);
//
//    @Resource
//    private BootstrapProperties bootstrapProperties;

    /**
     * 如果没有在worker 端配置 规则 是取不到值的 获取无效
     * @param key
     * @return
     */
    @Override
    Object doGetCache(String key) {
        return manualCache.getCache(key);
    }

    /**
     * 设置缓存 如果没有配置规则 设置无效
     *
     * @param key
     * @param value
     * @return
     */
    public boolean setCache(String key, Object value) {
        try {
            manualCache.setCache(key, value);
        } catch (Exception ex) {
            return false;
        }
        return true;
    }

    @Override
    public boolean isHotKey(String key) {
        return manualCache.isHotKey(key);
    }
}
